/*
  Calculate age and sort rating.
*/

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector> 
#include <algorithm> 

using namespace std;

struct date {
	char m[100];
	int day, month, year;
};

int convertMonth(string s)
{
	if (s == "january") return 1;
	if (s == "february") return 2;
	if (s == "march") return 3;
	if (s == "april") return 4;
	if (s == "may") return 5;
	if (s == "june") return 6;
	if (s == "july") return 7;
	if (s == "august") return 8;
	if (s == "september") return 9;
	if (s == "october") return 10;
	if (s == "november") return 11;
	if (s == "december") return 12;
	return -1;
}	

date today;
int age(date x)	
{		
	
	int res = today.year - x.year;
	if (today.month < x.month) return res-1;
	if (today.month > x.month) return res;
	if (today.day < x.day) return res-1;
	return res;
}

struct winner {
	int age, rate;
	vector<string> list;
};
vector <winner> w;

void update(int age, int rating, string name)
{
	for (int i = 0; i < w.size(); i++)
		if (w[i].age == age) 
		{
			if (w[i].rate == rating) w[i].list.push_back(name);
			else
				if (w[i].rate < rating) {
					w[i].rate = rating;
					w[i].list.clear();
					w[i].list.push_back(name);
				}
			return;
		}

	winner x;
	x.age = age;
	x.rate = rating;
	x.list.clear();
	x.list.push_back(name);
	
	w.push_back(x);	
}

bool cmp(winner x, winner y)
{
	return (x.age < y.age);
}
 
int main()
{		
	int N, M;
	scanf("%d\n", &N);
	for (int ntest = 1; ntest <= N; ntest++)
	{
		w.clear();
		scanf("%d %s %d\n", &today.day, today.m, &today.year);
		today.month = convertMonth(string(today.m));
		
		scanf("%d\n", &M);
		for (int i = 0; i < M; i++) 
		{
			char fn[100], ln[100];
			date birth;
			int rating;
		
			char c;
			scanf("%s %s %c %d %s %d %c %d", fn, ln, &c, &birth.day, birth.m, &birth.year, &c, &rating);
			string name = string(fn) + " " + string (ln);
			birth.month = convertMonth(string(birth.m));
			
			int diff = age(birth);
			update(diff, rating, name);
		}
		sort(w.begin(), w.end(), cmp);

		cout << "Contest " << ntest << ": " << today.day << " " << string(today.m) << " " << today.year << endl;
		cout << "All participants are winners with" << endl;
		for (int i = 0; i < w.size(); i++) 
		{
			cout << w[i].list[0] << " is best under " << w[i].age+1 << endl;
			if (w[i].list.size() > 1)
				for (int j = 1; j < w[i].list.size(); j++) cout << "and also " << w[i].list[j] << endl;
		}
	}
	return 0;
}
